package cn.oracle.config;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import java.lang.reflect.AnnotatedElement;


/**
 * @author wuyuhong
 * @date 2021/03/22 22:32
 * 这个类的作用相当于web.xml配置文件
**/ 
public class WebInit implements WebApplicationInitializer {
    @Override
    public void onStartup(javax.servlet.ServletContext servletContext) throws ServletException {
        AnnotationConfigWebApplicationContext ctx= new AnnotationConfigWebApplicationContext();
        ctx.register(SpringMVCConfig.class);
        ServletRegistration.Dynamic springmvc = servletContext.addServlet("springmvc", new DispatcherServlet(ctx));
//快捷生成返回类型，ctrl+alt+v
        //mapping映射
        springmvc.addMapping("/");
        //启动时机
        springmvc.setLoadOnStartup(1);
    }
}
